package cloudspace.vm.javassist.tests;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javassist.ClassPool;

import junit.framework.TestCase;
import cloudspace.vm.javassist.ConfigurableTranslatorLoader;
import cloudspace.vm.javassist.MalformedConfigurationException;
import cloudspace.vm.javassist.TranslatorProvider;

public class ExprEditorFactoryTest extends TestCase
{
	TranslatorProvider eeFactory;
	public void setUp()
	{
		eeFactory = TranslatorProvider.getExprEditorFactory();
	}
	public void tearDown()
	{
		//eeFactory.clear();
	}
	public void testGetExprEditorFactory()
	{
		 assertNotNull(eeFactory);
	}

	public void testAddConfigFile()
	{
		TranslatorProvider eeFactory = TranslatorProvider.getExprEditorFactory();
		try
		{
			eeFactory.addConfigFile(new File("src/configFiles/TranslatorConfig.conf"), new ClassPool());
		}
		catch (IOException e)
		{
			e.printStackTrace();
			fail("Could not open config file");
		}
	}

	public void testGetTranslators()
	{
		TranslatorProvider eeFactory = TranslatorProvider.getExprEditorFactory();
		try
		{
			eeFactory.addConfigFile(new File("src/configFiles/TranslatorConfig.conf"), new ClassPool());
		}
		catch (IOException e)
		{
			e.printStackTrace();
			fail("Could not open config file");
		}
		try
		{
			List<ConfigurableTranslatorLoader> translators = eeFactory.getTranslators();
			ConfigurableTranslatorLoader curTrans = translators.get(0);
			assertNotNull(curTrans);
		}
		catch(MalformedConfigurationException e)
		{
			e.printStackTrace();
			fail();
		}
			
	}

}
